const path = require('path')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const MiniCssExtract = require('mini-css-extract-plugin')

const CopyWebpackPlugin = require('copy-webpack-plugin')
module.exports = {
    entry: path.resolve(__dirname, '../src/index.js'),
    output: {
      filename: 'js/bundle.js',
      path: path.resolve(__dirname, '../dist')
    },
    resolve:{
      alias: {
        '@': path.resolve(__dirname, '../src'),
        modules: [
          path.resolve(__dirname, '../node_modules')
        ]
      }
    },
    module:{
      rules:[
        {
          test: /\.css$/,
          use: [{
            loader: MiniCssExtract.loader,
            options: {
              publicPath: '../'
            }
          },'css-loader','postcss-loader']
        },
        {
          test: /\.less$/,
          use: [{
            loader: MiniCssExtract.loader,
            options: {
              publicPath: '../'
            }
          },'css-loader','postcss-loader','less-loader']
        },
        {
          test: /\.html$/,
          loader: 'html-withimg-loader'
        },
        {
          test: /\.(png|jpeg|jpg)$/,
          use: [{
            loader: 'file-loader',
            options: {
              esModule: false,
              outputPath: 'img/'
            }
          }]
        },
        {
          test: /\.js$/,
          include: path.resolve(__dirname, '../src'),
          use: [{
            loader: 'babel-loader',
            options: {
              presets: ['@babel/preset-env'],
              plugins: ['@babel/plugin-proposal-class-properties','@babel/plugin-transform-runtime']
            }
          }]
        }
      ]
    },
    plugins:[
      new HtmlWebpackPlugin({
        template: path.resolve(__dirname, '../public/index.html'),
        filename: 'index.html'
      }),
      new MiniCssExtract({
        filename: 'css/index.css'
      }),
      new CopyWebpackPlugin({
        patterns: [
          {
            from: path.resolve(__dirname, '../doc'),
            to: path.resolve(__dirname, '../dist/doc')
          }
        ]
      })
    ]

}